package com.dycx.api.controller.manage.system;

import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import com.dycx.system.dto.RegionDTO;
import com.dycx.system.service.RegionService;
import com.dycx.system.vo.RegionVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping(value = "/manage/system/region")
public class RegionController {

    @Resource
    private RegionService regionService;

    /**
     * 刪除
     **/
    @WriterLog(bizType = BizTypeEnum.SYS_REGION, bizValue = "{#id}")
    @GetMapping("/delete")
    public RestResponse<Boolean> delete(int id) {
        return regionService.delete(id) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 添加
     **/
    @WriterLog(bizType = BizTypeEnum.SYS_REGION, bizValue = "{#dto.id}")
    @PostMapping("/create")
    public RestResponse<Boolean> create(@RequestBody @Valid RegionDTO dto) {
        return regionService.create(dto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改
     **/
    @WriterLog(bizType = BizTypeEnum.SYS_REGION, bizValue = "{#dto.id}")
    @PostMapping("/edit")
    public RestResponse<Boolean> edit(@RequestBody @Valid RegionDTO dto) {
        return regionService.edit(dto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 查询子级列表
     **/
    @GetMapping("/getChildList")
    public RestResponse<List<RegionVO>> getChildList(Integer parentCode) {
        return RestResponse.success(regionService.getChildList(parentCode));
    }

}
